<?php

namespace app\beautiful\controller\admin\appointment;

use app\BaseController;

use app\beautiful\model\appointment\AppointmentModel;

use app\common\logic\DataLogic;





class Kanban extends BaseController{

    public function show()

    {

        $day=$this->request->param('day');

        if(empty($day)) return $this->error('参数错误');

        if(false === strtotime($day.' 00:00:00')) return $this->error('参数错误');

        $where=[

            ['shop_id','=',$this->request->shopId],

            ['day','=',$day]

        ];



        $appointment_model= new AppointmentModel();

        $total=$appointment_model->where($where)->group('technician_id')->count();

        $appointment_model = $appointment_model->with(['technician']);

        $order=['count'=>'desc'];

        $field="technician_id,count(*) as count";

        $list=$appointment_model

            ->where($where)

            ->field($field)

            ->group('technician_id')

            ->order($order)

            ->select()

            ->toArray();





        $technician_ids=array_column($list,'technician_id');

        $appointment_data=AppointmentModel::with(['technician','member'])->where([

            ['shop_id','=',$this->request->shopId],

            ['day','=',$day],

            ['technician_id','in',$technician_ids]

        ])->select()->append(['status_means','operate_type_means','arrival_time_format','cancel_time_format'])->toArray();



        $technician_data=[];

        foreach($appointment_data as $k=>$v){

            $technician_data[$v['technician_id']][]=$v;

        }



        foreach ($list as $k => $v){

            $list[$k]['orders']=$technician_data[$v['technician_id']];

        }



        $return=[

            'total'=>$total,

            'list'=>$list

        ];

        return $this->success($return);

    }

}

